#ifndef XPM_H
#define XPM_H


#include <map>
#include <vector>


#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif


  class XPM {
      int height;
      int width;
      int nColours;
      std::vector<unsigned char> pixels;
      ColourDesired colourCodeTable[256];
      char codeTransparent;
      ColourDesired ColourFromCode( int ch ) const;
      void FillRun( Surface *surface, int code, int startX, int y, int x );
    public:
      explicit XPM( const char *textForm );
      explicit XPM( const char *const *linesForm );
      ~XPM();
      void Init( const char *textForm );
      void Init( const char *const *linesForm );

      void Draw( Surface *surface, PRectangle &rc );
      int GetHeight() const { return height; }
      int GetWidth() const { return width; }
      void PixelAt( int x, int y, ColourDesired &colour, bool &transparent ) const;
    private:
      static std::vector<const char *>LinesFormFromTextForm( const char *textForm );
  };


  class RGBAImage {

      RGBAImage( const RGBAImage & );
      RGBAImage &operator=( const RGBAImage & );
      int height;
      int width;
      float scale;
      std::vector<unsigned char> pixelBytes;
    public:
      RGBAImage( int width_, int height_, float scale_, const unsigned char *pixels_ );
      explicit RGBAImage( const XPM &xpm );
      virtual ~RGBAImage();
      int GetHeight() const { return height; }
      int GetWidth() const { return width; }
      float GetScale() const { return scale; }
      float GetScaledHeight() const { return height / scale; }
      float GetScaledWidth() const { return width / scale; }
      int CountBytes() const;
      const unsigned char *Pixels() const;
      void SetPixel( int x, int y, ColourDesired colour, int alpha = 0xff );
  };


  class RGBAImageSet {
      typedef std::map<int, RGBAImage*> ImageMap;
      ImageMap images;
      mutable int height;
      mutable int width;
    public:
      RGBAImageSet();
      ~RGBAImageSet();

      void Clear();

      void Add( int ident, RGBAImage *image );

      RGBAImage *Get( int ident );

      int GetHeight() const;

      int GetWidth() const;
  };

  #ifdef SCI_NAMESPACE
}
  #endif

#endif
